#include<bits/stdc++.h>
using namespace std;
int n,m,a1[100010],c[100010],d[100010],a[100010],k;
int main(){
    //freopen("arena.in","r",stdin);
    //freopen("arena.out","w",stdout);


    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);


    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a1[i];
        for(int j=1;j<=m;j++){
            cin>>c[j];
        }
        for(int j=1;j<=n;j++){
            if(pow(2,i)>=n){
                k=i;
                break;
            }
        }
        for(int j=1;j<=k;j++){
            cin>>d[j];
        }
    }
    int t;
    for(int i=1;i<=t;i++){
        int x1,x2,x3,x4;
        cin>>x1>>x2>>x3>>x4;
        a[i]=a1[i]^(x1%4);
    }
    cout<<n<<m<<k<<a[n];
    return 0;
}
